package com.action;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.bean.ResponseBean2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/weixinMiniapp")
public class WeixinMiniAppLoginAction {

    @Autowired
    private WxMaService  wxMaService;

    /**
     * 根据code获取session
     * @param code
     * @return
     * @throws Exception
     */
    @RequestMapping("/login")
    public ResponseBean2  login(String code,String iv,String encryptedData) throws Exception
    {
        WxMaJscode2SessionResult  wxMaJscode2SessionResult =  wxMaService.getUserService().getSessionInfo(code);
        WxMaUserInfo  wxMaUserInfo =  wxMaService.getUserService().getUserInfo(wxMaJscode2SessionResult.getSessionKey(),encryptedData,iv);
        System.out.println(wxMaUserInfo);
        return  new ResponseBean2(200,"获取成功",wxMaUserInfo);
    }

}
